<template>
    <div class="row">
        <el-checkbox v-model="comp.enabled">{{ comp.__classname__ }}</el-checkbox>
        <el-button round size="small" :icon="Document" @click="gm.toConsole(comp)"></el-button>
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>CustomMaterial</el-text>
        <el-input size="small" disabled :value="gm.targetName(comp.customMaterial)" />
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>Color</el-text>
        <el-color-picker size="small" color-format="hex" show-alpha v-model="Model.color" />
        <el-input size="small" v-model="Model.color" />
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>SkeletonData</el-text>
        <el-input size="small" disabled :value="gm.targetName(comp.skeletonData)" />
    </div>

    <!-- <div class="row-start">
        <el-text class="span-title" truncated>DefaultSkin</el-text>
        <el-select v-model="Model.defaultCacheMode" size="small" readonly>
            <el-option v-for="item in defaultCacheMode" :key="item.value" :label="item.name" :value="item.value" />
        </el-select>
    </div> -->

    <div class="row-start">
        <el-text class="span-title" truncated>Animation</el-text>
        <el-select v-model="Model.animation" size="small">
            <el-option v-for="item in animations" :key="item.value" :label="item.name" :value="item.name" />
        </el-select>
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>AnimationCacheMode</el-text>
        <el-select v-model="Model.defaultCacheMode" size="small" readonly>
            <el-option v-for="item in defaultCacheMode" :key="item.value" :label="item.name" :value="item.value" />
        </el-select>
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>PremultipliedAlpha</el-text>
        <el-checkbox v-model="comp.premultipliedAlpha" />
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>Loop</el-text>
        <el-checkbox v-model="comp.loop" />
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>TimeScale</el-text>
        <el-input-number size="small" :controls="false" :step="0.1" v-model="comp.timeScale" />
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>UseTint</el-text>
        <el-checkbox v-model="comp.useTint" />
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>EnableBatch</el-text>
        <el-checkbox v-model="comp.enableBatch" />
    </div>


    <div class="row-start">
        <el-text class="span-title" truncated>DebugSlots</el-text>
        <el-checkbox v-model="comp.debugSlots" />
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>DebugBones</el-text>
        <el-checkbox v-model="comp.debugBones" />
    </div>

    <div class="row-start">
        <el-text class="span-title" truncated>DebugMesh</el-text>
        <el-checkbox v-model="comp.debugMesh" />
    </div>
</template>

<script lang="ts" setup>
import { Document } from '@element-plus/icons-vue'
import gm from './gm'

const props = defineProps<{
    comp: CCComponent,
    update: Number,
}>()
const defaultCacheMode = [
    { name: 'UNSET', value: -1 },
    { name: 'REALTIME', value: 0 },
    { name: 'SHARED_CACHE', value: 1 },
    { name: 'PRIVATE_CACHE', value: 2 },
]
// const skins = props.comp.skeletonData ? gm.getEnum(props.comp.skeletonData.getSkinsEnum()) : []
const animations = props.comp.skeletonData ? gm.getEnum(props.comp.skeletonData.getAnimsEnum()) : []

class Model{
    static get comp() {
        return props.comp
    }

    static get color() {
        return gm.toHexColor(this.comp.color)
    }

    static set color(value: string) {
        this.comp.color = gm.toCCColor(value)
    }

    static get animation() {
        return this.comp.animation
    }

    static set animation(value: string) {
        this.comp.setAnimation(0, value, this.comp.loop)
    }

    static get defaultCacheMode() {
        return this.comp.defaultCacheMode
    }

    static set defaultCacheMode(value: number) {
        this.comp.setAnimationCacheMode(value)
    }
}
</script>